<template>
  <div>
      <div class="city-fixed" v-if="false">
      <router-link to="/city">
        <span>苏州</span>
        <i class="iconfont icon-xiala-"></i>
      </router-link>
    </div>
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white" v-if="false">
      <van-swipe-item>1</van-swipe-item>
      <van-swipe-item>2</van-swipe-item>
      <van-swipe-item>3</van-swipe-item>
      <van-swipe-item>4</van-swipe-item>
    </van-swipe>
   
  <div :class="{active:active==true}">
     <Title v-if="show"/>
	<!-- 导航选择 -->
      <van-tabs v-model:active="status" route title-active-color="#ff5f16" line-width="55px" line-height="2px" color="#ff5f16" >
        <van-tab title="正在热映" to="/showing"></van-tab>
        <van-tab title="即将上映" to="/coming"></van-tab>
      </van-tabs>
  </div>


	<!-- 二级路由出口 -->
	<router-view></router-view>
  </div>
</template>

<script>
import { onMounted, reactive, toRefs ,ref, watch} from 'vue';
import Title from '@/components/Title'
import { useStore } from 'vuex';
import { useRouter } from 'vue-router';

export default {
	name:'Movie',
  components:{
    Title
  },
	setup(){
		const state = reactive({
			 status:0,
      show:false,
      active:false
		});
		
    onMounted(()=>{
       window.addEventListener('scroll',handleScroll,true);
      state.status = store.state.status
    })
    const handleScroll = (e) => {
     let scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
      if (e.target.scrollTop>150) {
        state.active = true
        state.show = true
      }else if(e.target.scrollTop==0){
        state.active = false
          state.show = false
      }

    }
      
      const time = ref(null)
      const store = useStore();
      const router = useRouter();

   
      // 监听路由变化修改选中状态
    watch(()=>router.currentRoute.value.path,()=>{
      let path = router.currentRoute.value.path
      if (path =='/showing') {
        store.commit('Modification',0)
       
      }else{
         store.commit('Modification',1)
      }
    })
        
		return {
			...toRefs(state),
		}
	}
};
</script>

<style scoped lang="less">

.active{
  position: fixed;
  top: 0;
  background: white;
  z-index: 999;
  width: 100%;
}

.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
div/deep/.van-tabs__wrap{
	// border-bottom: 1px solid #ededed ;
	height: 49px;
}

// 定位
.city-fixed {
  position: absolute;
  top: 18px;
  left: 7px;

  z-index: 10;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.2);
  height: 30px;
  line-height: 30px;
  border-radius: 15px;
  text-align: center;
  padding: 0 5px;

  & a{
  color: #fff;
	.iconfont {
    font-size: 15px;
  }
  }
}
.van-tabs{
  border-bottom: 1px solid #ededed;
}
</style>
